/************************************************************
 * @file: main.h
 * @author: Novosns MCU Team
 * @version: V2.0
 * @data: 2023/05/25
 * @brief: Main header file for bipolar motor project.
 * @note: 
 * @Copyright (C) 2023 Novosense All rights reserved.
 ************************************************************/

#ifndef __MAIN_H
#define __MAIN_H

/*#############################################################################
  START OF CONFIGURATION SECTION

  MODIFY TO THE APPLICATION NEEDS
#############################################################################*/
/*!  \addtogroup  scheduling_configuration
 \{ */
/** System clock in kHz */
#define MAIN_FSYS_KHZ (32000)
/** Number of tasks in the application. \n range: 1..8 */
#define MAIN_NUMBER_OF_TASK (3)
/** Defines the scheduling tick in <b>us</b> */
#define MAIN_SCHEDULING_TICK_TIME_US (1000)
/** Prescaler value for the timer */
#define MAIN_SCHEDULING_TIMER_CLOCK (1)

#define SYSCTRL_UNLOCK_KEY            0x87e4
#define SYSCTRL_TRIM_REG_UNLOCK_KEY1  0x8a3d
#define SYSCTRL_TRIM_REG_UNLOCK_KEY2  0x19ec

/*  \} */
/*#############################################################################
  END OF CONFIGURATION SECTION
#############################################################################*/

/** Timer register value calculation:
   it depends on the value of CLKMUX register,
   the scheduling period (MAIN_SCHEDULING_TICK_TIME_US), and the system frequency (fsys=20 MHz).
   Timer reload value = (fsys) * (scheduling time)
*/
#define MAIN_TIMER_RELOAD (((MAIN_FSYS_KHZ / (MAIN_SCHEDULING_TIMER_CLOCK + 1)) * MAIN_SCHEDULING_TICK_TIME_US) / 1000)

#if MAIN_TIMER_RELOAD < 1
#error SCHEDULER_TICK to low, select a higher tick or timer clock
#elif MAIN_TIMER_RELOAD > 65535
#error MAIN_SCHEDULING_TICK_TIME_US to high, select a lower tick or timer clock
#endif

#endif /* __MAIN_H */
